// Copyright (c) 2023 刻BITTER
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.


#include "app.hpp"


const ioxx::Pin LED_PIN = LED_BUILTIN;

scheduler_basic::DelayCallback3<TimeSource, 8> dcb{0, 0};


TimeType task_blink() {
    LED_PIN.toggle();
    return 800;
}


TimeType task_hello() {
    static auto c = 0;
    log_line("HELLO = ", ++c);
    return 1500;
}


void yield() {
    static bool lock = false;
    if (lock) {
        // 禁止重入
        return;
    }

    lock = true;
    dcb.tick();
    lock = false;
}


void loop() {
    yield();
}


void setup() {
    pinMode(m128::RGB_PIN, OUTPUT);

    begin_log();

    dcb.add_task(task_blink, 0);
    dcb.add_task(task_hello, 0);
}
